package com.aop;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect// 当前类设置为切面
@Component
public class AnnoAdvice {
    @Pointcut("execution(* com.dao.impl.UserDaoImpl.*(..))")//指定要切的类
    public void pointcut(){

    }

    @Before("pointcut()")
    public void before(JoinPoint joinpoint){
        System.out.println("这是前置通知");
        System.out.println("目标类是："+joinpoint.getTarget());
        System.out.println("被织入增强处理的目标为："+joinpoint.getSignature().getName());
    }

    @AfterReturning("pointcut()")
    public void afterReturning(JoinPoint joinPoint){
        System.out.print("这是返回通知");
        System.out.println("被织入增强处理的目标为："+joinPoint.getSignature().getName());
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws  Throwable{
        System.out.println("这是环绕通知之间的部分");
        Object object = point.proceed();
        System.out.println("这是环绕通知之间的部分");
        return object;
    }

    @AfterThrowing("pointcut()")
    public void afterException(){
        System.out.println("通知异常");
    }
    @After("pointcut()")
    public void after(){
        System.out.println("这是后置通知！");
    }
}
